<?php include('login/trancar.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<?php
		$titulo = "Controle &raquo; Filias";
		require_once ("includes/header.php"); 
	?>
	<script type="text/JavaScript">
      function mascara_cep(cep)
      {
              var mydata = '';
              mydata = mydata + cep;
              if (mydata.length == 5)
              {
                  mydata = mydata + '-';
                  document.forms[0].cep.value = mydata;
              } 
      }
    </script>
</head>
<body>
			<?php 
				include('includes/topoemenu.php');
				require_once('includes/db.php');
				if ($_POST)
				{
					$cnpj = $_POST['cnpj'];
					$razaosocial = $_POST['razaosocial'];
					$endereco = $_POST['endereco'];
					$bairro = $_POST['bairro'];
					$cidade = $_POST['cidade'];
					$estado = $_POST['estado'];
					$cep = $_POST['cep'];
                                        $email = $_POST['email'];
					$telefone = $_POST['telefone'];
					
                                        
					if ($cnpj == '' || $razaosocial == '' || $endereco == '' || $bairro == '' || $cidade == '' || $estado == '' || $cep == '' || $email == '' || $telefone == '')
					{
						echo "<script>alert('Preencha todos os campos')</script>";					
					}
					else{
						$cad = mysql_query ("INSERT INTO tb_filias(CNPJ,Razao_Social,Endereco,Bairro,Cidade,Estado,CEP,email,Telefone) 
						values('$cnpj','$razaosocial','$endereco','$bairro','$cidade','$estado','$cep','$email','$telefone') ") 
						or die (mysql_error());
						if ($cad != '')
							echo "<script>alert('Cadastro foi efetuado com sucesso');</script>";
				
                                             }  
                                        }
			 ?>
			 	
			<div id="principal">
				<form action="<?php $_SERVER['PHP_SELF']?>" method="post">
					<fieldset>
						<legend class="titulo">Cadastro de Filias &darr; </legend>
						<label>CNPJ</label>
						<input type="text" name="cnpj" maxlength="14"  onfocus="this.style.backgroundColor='#fff';" onblur="this.style.backgroundColor='#EEE';"/><br />
						<label>Razao Social</label>
						<input type="text" name="razaosocial" maxlength="40"/><br />
						<label>Endereco</label>
						<input type="text" name="endereco" maxlength="40" /><br />
						<label>Bairro</label>
						<input type="text" name="bairro" maxlength="15" /><br />
						<label>Cidade</label>
						<input type="text" name="cidade" maxlength="25" /><br />
					
						<label>Estado</label>
						<select name="estado">
                                                        <option>RJ</option>
							<option>SP</option>	
							<option>PR</option>					
						</select><br />
						<label>CEP</label>
						<input class="camp" type="text" name="cep" size="9" maxlength="9" /><br />
						<label>Email</label>
						<input type="text" name="email" maxlength="20" /> <br />
						<label>Telefone</label>
						<input type="text" name="telefone" maxlength="30" /> <br />
						
						<input class="botao" type="submit" name="enviar" value="Cadastrar" /> 
					</fieldset>				
				</form>
			</div> <!-- Fim da div#principal -->
			<?php include('includes/fimerodape.php'); ?>
</body>
</html>